﻿using Newtonsoft.Json;
using Serilog.Events;
using Serilog.Formatting;

namespace Admin.WebApi.Infrastructure.Formatter
{
    public class CustomElasticsearchFormatter : ITextFormatter
    {
        public void Format(LogEvent logEvent, TextWriter output)
        {
            var elasticsearchTemplate = new ElasticsearchTemplate
            {
                app_id = "api-test",
                message = logEvent.Exception!=null ? logEvent.Exception.Message : JsonConvert.SerializeObject(logEvent.Properties),
                level = logEvent.Level.ToString()
            };
            output.Write(JsonConvert.SerializeObject(elasticsearchTemplate));
        }
    }
}